package sy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.pageModel.Room;
import sy.service.RoomServiceI;
import sy.util.StringUtil;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * Created by Administrator on 2016-07-06.
 */
@Controller
@RequestMapping("roomController")
public class RoomController  extends BaseController  {
    @Autowired
    private RoomServiceI roomService;


    @Autowired
    private HttpSession session;
    @RequestMapping("/datagrid.action")
    @ResponseBody
    public DataGrid findPicAction(Room room){
        return roomService.findRoomDataGird(room);
    }

    @RequestMapping("/find_code.action")
    @ResponseBody
    public Json findAction(String types){
        Json js=new Json();
//        js.setObj(findOption(roomService.findCodeList(types)));
        return js;
    }
    @RequestMapping("/add_currency.action")
    @ResponseBody
    public Json addPicAction(Room room){
        int rows=0;
        Map map= StringUtil.findMap(room.getPic());
        room.setPic((String) map.get("pic"));
        room.setId((String) map.get("id"));
        try {
            rows=roomService.addRoomService(room);
            if (rows>0)  logUserAction(session,"roomController/add_currency.action",room.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"添加");
        return js;
    }
    @RequestMapping("/edit_currency.action")
    @ResponseBody
    public Json editPicAction(Room room){
        int rows=0;
        room.setPic(StringUtil.findStr(room.getPic()));
        try {
            rows=roomService.editRoomService(room);
            if (rows>0)  logUserAction(session,"roomController/edit_currency.action",room.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"修改");
        return js;
    }


    @RequestMapping("/remove_currency.action")
    @ResponseBody
    public Json removePicAction(Room room){
        int rows=0;
        try {
            rows= roomService.deleteRoomService(room.getIds());
            if (rows>0)  logUserAction(session,"roomController/remove_currency.action",room.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"删除");
        return js;
    }
}
